{extend name="layout/base" /}

{block name="title"}余额支付 - 我的购物车 - {mall:config name="mall.sitename"/}{__block__}{/block}

{block name="meta"}
{__block__}
<link href="__ADDON__/__STYLE__/css/cart.css" rel="stylesheet">
<link rel="stylesheet" href="__CDN__/assets/libs/nice-validator/dist/jquery.validator.css">
<style>
	.mall-table{margin-top:20px; color: #333;font: 12px/150% "Hiragino Sans GB","Microsoft Yahei",arial,宋体,"Helvetica Neue",Helvetica,STHeiTi,sans-serif;}
	.mall-login-tr{height:30px;}
</style>
{/block}

{block name="body"}
<body class="shopping_cart_page">
{/block}

{block name="main"}
<div class="container">
    <div class="pay-sbox-head">
    	<a href='{$Request.root.true}'>首页</a>&nbsp;&gt;&nbsp;支付
    </div>
    <div>
    	<div class="pay-tip2"></div>
    </div>
    <div class='pay-sbox'>
    	<div class="balance-box">
    	    <div class='tips-box'>待支付订单总额：<span class="mall-fred">￥{$needPay}</span></div>
		    <div class='mall-wallet-box'>
	        	<div class='mall-wallte-item'>
	        	钱包余额：<span class="mall-fred">￥{$money}</span>
	        	</div>
                <div style='float:right;'>支付：<span class="mall-fred">￥{$needPay}</span></div>
	        </div>
	        {if ($money>=$needPay)}
	        <div class="pbox">
	        	<input type='hidden' id='c-key' value='{$paykey}' class='j-ipt' autocomplete="off" />
	        	{if ($hasPayPwd==1)}
	        	支付密码：<input type='password' class='u-query j-ipt' id='c-payPwd' name='payPwd' autocomplete='off'>
	        	<a class='pbox-tip' maxlength='6' target='_blank' href='/user/mall/user/Security'>忘记密码?</a>
	        	{else}
	        	您尚未设置支付密码，请先设置支付密码
				<div id="paypwd-box" class="j-paypwd-box" style="display:none;padding:20px;">
					<table class="mall-table">
						{:token()}
						<tr class="mall-login-tr">
							<td align='right'>支付密码：</td>
							<td><input type="password" class='j-ipt' id="c-payPwd" name="payPwd" style="width:250px;" maxlength="6" aria-required="true"></td>
						</tr>
						<tr class="mall-login-tr">
							<td align='right'>确认支付密码：</td>
							<td><input type="password" class="ipt n-invalid" id="c-reNewPass" name="reNewPass" style="width:250px;" maxlength="6" aria-required="true" aria-invalid="true"></td>
						</tr>
					</table>
				</div>
	        	{/if}
	        </div>
	        <div class="pbox2">
	        {if($hasPayPwd==1)}
	        	<button class="pay-btn" type="button" style="width:100px;height: 30px;" onclick='javascript:payByWallet()'>确认支付</button>
	        {else}
	        	<button class="pay-btn" type="button" style="width:100px;height: 30px;" onclick='javascript:setPaypwd()'>去设置支付密码</button>
	        {/if}
	        </div>
	        {else}
	        <div class="pbox">
	         	<img src='__ADDON__/__STYLE__/images/icon_jinggao.png'>&nbsp;很抱歉，您的钱包余额不足，不能进行支付。<a class='pbox-tip' href='javascript:void(0)' onclick="javascript:history.go(-1)">返回上一页</a>。
	        </div>
	        {/if}
        </div>
    </div>
</div>
{/block}

{block name="js"}
{__block__}
<script>
    /**
     *余额支付
     */
    function payByWallet(){
        var params = getParams('.j-ipt');
        $.ajax({
            url: '/addons/mall/wallets/payByWallet',
            type: 'post',
            dataType: 'json',
            data: params,
            success: function (ret) {
                if(ret.code){
                    if(ret.msg) Toastr.success(ret.msg);
                    window.location = ret.url?ret.url:'/user/mall/order/myorder.html?ref=addtabs';
                }else{
                    if(ret.msg) Toastr.error(ret.msg);
                }
            },
        });
    }

    /**
     *设置支付密码
     */
    function setPaypwd(){
        layerbox =	Layer.open({
            title:['设置支付密码','text-align:left'],
            type: 1,
            area: ['450px', '240px'], //宽高
            content: $('.j-paypwd-box'),
            btn: ['设置支付密码，并支付订单', '关闭'],
            yes: function(index, layero){
                var newPass = $.trim($("#c-payPwd").val());
                var reNewPass = $.trim($("#c-reNewPass").val());
                if(newPass==""){
                    Toastr.error("请输入支付密码！");
                    return false;
                }
                if(reNewPass==""){
                    Toastr.error("请输入确认支付密码！");
                    return false;
                }
                if(newPass!=reNewPass){
                    Toastr.error("密码不一致！");
                    return false;
                }
                $.ajax({
                    url: '/addons/mall/user/editPayPass',
                    type: 'post',
                    dataType: 'json',
                    data: {newPass:newPass,reNewPass:reNewPass},
                    success: function (ret) {
                        if(ret.code){
                            Toastr.success(ret.msg,function(){
                                layer.close(layerbox);
                                payByWallet();
                            });
                        }else{
                            if(ret.msg) Toastr.error(ret.msg);
                        }
                    },
                });

                return false;
            },
            btn2: function(index, layero){}
        });

    }

</script>
{/block}